lapply(c("sf", "terra", "ggplot2", "rasterVis", "gstat"),
library, character.only = TRUE)
# 1. Create a 50 * 50 template SpatRaster
xy_rast <- rast(
ncols = 50, nrows = 50, xmin = 0.5, xmax = 50.5, ymin = 0.5, ymax = 50.5)
# 2. Define the gstat object and interpolate to the raster
set.seed(2)
gdummy <- gstat(
formula = z ~ 1, locations = ~x + y, dummy = TRUE, beta = 1,
model = vgm(psill = 0.35, range = 30, model = 'Sph'), nmax = 20)
r <- interpolate(xy_rast, gdummy, nsim = 1)
# Plot
levelplot(
r, scales = list(draw = FALSE), axes = FALSE,
colorkey = list(axis.line = list(col = "#FAF0E6"),
axis.text = list(col = "#FAF0E6")))